package myNewProject.notifier;

import myNewProject.utils.CustomResult;
import myNewProject.utils.MyEmailUtil;

import java.util.List;

public class NoticeByEmail implements Notifier{
    @Override
    public void notice(List<CustomResult> parsedResult, String[] keyword) {
        StringBuilder stringBuilder = new StringBuilder();
        for (String s : keyword) {
            stringBuilder
                    .append("=== === === === ===\n")
                    .append("当前检索关键字：")
                    .append(s)
                    .append('\n')
                    .append("=== === === === ===\n\n");
            for (CustomResult c : parsedResult) {
                if (c.getTitle().contains(s)) {
                    stringBuilder.append(c);
                }
            }
        }
        try {
            MyEmailUtil.send("1316856223@qq.com", String.valueOf(stringBuilder));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void noticeBefore(List<CustomResult> parsedResult , String[] keywords, String timestamp) {
    }

    @Override
    public List<CustomResult> filter(List<CustomResult> parsedResult, String keyword) {
        return null;
    }
}
